package com.heima.user.interceptor;


import com.heima.user.util.AppThreadLocalUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.stereotype.Component;


/**
 * feign拦截器,在每次使用fei接口进行远程调用的时候,会拦截请求,
 * 给请求头加上userId,因为fei调用会直接越过网关访问自媒体微服务,
 * 直接访问是会被拦截的,加上userId后就不会被拦截
 */
@Component
public class FeignHeaderInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        requestTemplate.header("userId", AppThreadLocalUtil.getUser().getId() + "");
    }
}
